﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameController : MonoBehaviour
{

    public GameObject pot1;
    public GameObject pot2;

    //神经猫
    public GameObject cat;

    // 列数
    public int columnNum = 9;

    // 行数
    public int rowNum = 9;

    //偏移值
   // float xOff = -2.25f;
    //float yOff = -3f;

    void Start ()
    {
     /*
      * 1.for循环，生成一行pot1
      * 2.实例化、生成位置、生成间隔
      * 3.看偏移数值，定义数值，加到生成的position中去
      * 4.镶嵌一列for循环，y轴也乘以0.5的距离间隔
      */

        for (int rowIndex = 0; rowIndex < rowNum; rowIndex++)
        {
            for (int columnIndex = 0; columnIndex < columnNum; columnIndex++)
            {
                GameObject o = Instantiate(pot1);
                o.transform.parent = this.transform;//生成的位置
                //o.transform.position = new Vector3(0.5f * columnIndex + xOff,0.5f * rowIndex + yOff, 0f);//生成的距离间隔

                //重构
                Item item = o.GetComponent<Item>();
                item.Goto(rowIndex,columnIndex);
                item.game = this;
            }
        }
        MoveCat(4,4);     
    }

    void MoveCat(int rowIndex, int columnIndex)
    {
        Item item = cat.GetComponent<Item>();
        item.Goto(rowIndex, columnIndex);
    }

    public void Select(Item item)
    {
        Debug.Log("Select"+item);
        MoveCat(item.rowIndex, item.columnIndex);
        Debug.Log(item.rowIndex+","+item.columnIndex);
     
    }
}
